﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;

namespace Husb.Data
{
    public class UnitOfWork<T> : IUnitOfWork
        where T : DBContext, new()
    {
        private readonly IDBFactory<T> databaseFactory;
        private T dataContext;

        public UnitOfWork(IDBFactory<T> databaseFactory)
        {
            this.databaseFactory = databaseFactory;
        }

        protected T DataContext
        {
            get { return dataContext ?? (dataContext = databaseFactory.Get()); }
        }

        public void Commit()
        {
            DataContext.Commit();
        }
    }
}
